package cn.itcast.manage;

import cn.itcast.bean.UmPassword;
import cn.itcast.bean.User;
import cn.itcast.dao.AddServlet;
import cn.itcast.dao.ListMessge;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String unum = req.getParameter("unum");
        String password = req.getParameter("password");
        resp.setContentType("text/html;charset=UTF-8");
        UmPassword umPassword = new UmPassword();
        AddServlet a = new AddServlet();
        List<UmPassword> list = a.find();
        for (UmPassword umPassword1 : list) {
            if(umPassword1.getUid().equals(unum)){
                umPassword.setUid(unum);
                umPassword.setPassword(password);
                a.listUm(umPassword);
                resp.sendRedirect("/login.jsp");
                return;
            }
        }
        resp.getWriter().write("用户名不存在");
        resp.setHeader("refresh","2;url=/update.jsp");



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
